package com.tcs.reptile.accept.impl;

import java.util.Map;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.google.common.collect.Maps;
import com.tcs.model.porxypool.proxyPoolBean;
import com.tcs.reptile.accept.PCAccept;
import com.tcs.util.constant.SystemConstants;

/**
 * PC端爬虫参数配置
 */
@Service(value="pcAccept")
@Scope(value="singleton")
public class PCAcceptImpl implements PCAccept<proxyPoolBean> {

	@Override
	public Map<String, String> getAccecptHeader(Map<String, String> params) {
		String host = params.get(SystemConstants.ReptileConstants.URL).
				substring(params.get(SystemConstants.ReptileConstants.URL).indexOf("://") + SystemConstants.ReptileConstants.SUB,
						params.get(SystemConstants.ReptileConstants.URL).indexOf("com/") + SystemConstants.ReptileConstants.SUB);
		Map<String, String> returnMap = this.returnMap();
		returnMap.put("Host", host);
		return returnMap;
	}
	
	@Override
	public Map<String, String> getAccecptHeader(String url) {
		String host = url.substring(url.indexOf("://") + SystemConstants.ReptileConstants.SUB,
				url.indexOf("com/") + SystemConstants.ReptileConstants.SUB);
		Map<String, String> returnMap = this.returnMap();
		returnMap.put("Host", host);
		return returnMap;
	}
	
	@Override
	public String getUserAgent() {
		return "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36";
	}
	
	@Override
	public Map<String, String> returnMap() {
		Map<String,String> returnMap = Maps.newHashMap();
		returnMap.put("Connection", "keep-alive");
		returnMap.put("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,image/wxpic,image/sharpp,image/apng,*/*;q=0.8");
		returnMap.put("Accept-Encoding", "gzip, deflate");
		returnMap.put("Accept-Language", "zh-CN,en-US;q=0.8");
		return returnMap;
	}
	
	@Override
	public proxyPoolBean getAccecptHeader(proxyPoolBean t) {
		return null;
	}
	
	@Override
	public boolean check() {
		return false;
	}

}
